package utils;

import indexer.SerializableHawar;
import java.util.ArrayList;

@SuppressWarnings("serial")
public class FileCollections extends SerializableHawar {
	private static String FILE_NAME = "file_collections.haw";
	private ArrayList<String> arrayFiles;
	private ArrayList<String> arrayDirectories;
	private ArrayList<String> arrayDirectoriesHistory;

	public FileCollections() {
		arrayFiles = new ArrayList<String>();
		arrayDirectories = new ArrayList<String>();
		arrayDirectoriesHistory = new ArrayList<String>();
		super.setFileName(FileCollections.FILE_NAME);
	}

	// ///////// if the arrays are empty ///////////
	public boolean directoriesIsEmpty() {
		return arrayDirectories.isEmpty();
	}

	public boolean filesIsEmpty() {
		return arrayFiles.isEmpty();
	}

	public boolean historyDirectoriesIsEmpty() {
		return arrayDirectoriesHistory.isEmpty();
	}

	// ///////// adding files and directories ///////////
	public void addDirectory(String dir) {
		arrayDirectories.add(dir);
	}

	public void addFile(String file) {
		arrayFiles.add(file);
	}

	public void addDirectoryHistory(String dir) {
		arrayDirectoriesHistory.add(dir);
	}

	// ///////// getting files and directories ///////////
	/**
	 * If arrayDirectory is not empty, returns the last directory, else, returns null
	 * @return lastDirectory
	 */
	public String getLastDirectory() {
		String lastDirectory = null;
		if (!arrayDirectories.isEmpty())
			lastDirectory = arrayDirectories.get(arrayDirectories.size() - 1);
		return lastDirectory;
	}

	/**
	 * @return lastDirectoryI
	 */
	public int getLastDirectoryIndex() {
		int lastDirectoryIndex = -1;
		if (!arrayDirectories.isEmpty())
			lastDirectoryIndex = arrayDirectories.size() - 1;
		return lastDirectoryIndex;
	}

	/**
	 * If arrayFiles is not empty, returns the last file, else, returns null
	 * @return lastFile
	 */
	public String getLastFile() {
		String lastFile = null;
		if (!arrayFiles.isEmpty())
			lastFile = arrayFiles.get(arrayFiles.size() - 1);
		return lastFile;
	}

	// ///////// removing files and directories ///////////
	/**
	 * Removes a specific directory from the array
	 * @param index
	 */
	public void removeDirectory(int index) {
		arrayDirectories.remove(index);
	}

	/**
	 * Removes the last directory from the array
	 */
	public void removeLastDirectory() {
		arrayDirectories.remove(arrayDirectories.size() - 1);
	}

	// ///////// get the complete arrays ///////////
	public ArrayList<String> getFiles() {
		return arrayFiles;
	}

	public ArrayList<String> getDirectories() {
		return arrayDirectories;
	}

	public ArrayList<String> getDirectoriesHistory() {
		return arrayDirectoriesHistory;
	}
}
